#import "RNStepper.h"
#import "RNStepperCell.h"

@implementation RNStepper

-(void)awakeFromNib {
    NSRect frame = [self frame];
    frame.size.height = 18;
    [self setFrame:frame];
}

- (void)mouseDown:(NSEvent *)theEvent {
    NSPoint eventPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
    NSRect textRect = [(RNStepperCell *)[self cell] textAreaRectForBounds:[self bounds]];
    if ([self mouse:eventPoint inRect:textRect]) {
        [[self cell] selectWithFrame:[self bounds] inView:self editor:[[NSApp mainWindow] fieldEditor:YES forObject:self] delegate:self start:0 length:[[self stringValue] length]];
        return;
    }
    [[self cell] trackMouse:theEvent inRect:[self bounds] ofView:self untilMouseUp:YES];
}

- (void)resetCursorRects {
    [self addCursorRect:[(RNStepperCell *)[self cell] textAreaRectForBounds:[self bounds]] cursor:[NSCursor IBeamCursor]];
}

-(BOOL)becomeFirstResponder {
    // TODO: SET FIELD EDITOR AS FIRST RESPONDER
    [[self cell] selectWithFrame:[self bounds] inView:self editor:[[NSApp mainWindow] fieldEditor:YES forObject:self] delegate:self start:0 length:[[self stringValue] length]];
    return YES;
}

@end
